﻿namespace NTLib.Core.Collection
{
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Extension methods to improve the queue manipulation.
    /// </summary>
    public static class QueueExtensions
    {
        #region Methods

        /// <summary>
        /// Removes the item. in a specific queue.
        /// </summary>
        /// <remarks>
        /// Before usign this methods be aware this will cost performance.
        /// Thinks of your container choice before using this methods.
        /// </remarks>
        public static void RemoveItem<T>(this Queue<T> items, T item)
        {
            var litem = items.ToList();
            litem.Remove(item);

            items.Clear();
            foreach (var it in litem)
            {
                items.Enqueue(it);
            }
        }

        #endregion
    }
}
